package dynamicJsonVerifyer.verifyers;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import dynamicJsonVerifyer.Const.*;
import dynamicJsonVerifyer.Const.BaseVerifyDataType;

import java.util.Map;

public class ArrayVerifyer extends FieldTypeVerifyer{

    @Override
    protected String getType() {
        return BaseVerifyDataType.array;
    }

    @Override
    protected boolean verifyType(JSONObject verifyMetadata, Object appointVaildData) {
        if(appointVaildData instanceof JSONArray){
            int size = ((JSONArray)appointVaildData).size();
            Integer maxSize = verifyMetadata.getInteger(VaildMetadataItem.arrayMaxSize);
            Integer minSize = verifyMetadata.getInteger(VaildMetadataItem.arrayMinSize);
            if(maxSize!=null && !(maxSize>=size)) return false;
            if(minSize!=null && !(minSize<=size)) return false;
            return true;
        }
        return false;
    }
}
